<extend name="Public/base" />
<block name="body">
	<div class="row">
		<div class="col-md-12">
			<!-- BEGIN EXAMPLE TABLE PORTLET-->
			<div class="portlet-body" id="cont">
				<div class="table-toolbar">
					<div class="btn-group" style="float:left">
						<a href="{:U('add')}" class="btn green">
							新 增 
						</a>
					</div>
				</div>

				<div class="clearfix"></div>

				<table class="table table-striped table-bordered table-hover dataTable" id="checkboxtable">
					<thead>
						<tr pid="0">
							<th width="5%">排序</th>
							<th>分类名称</th>
							<th>操作</th>
						</tr>
					</thead>

					<tbody>
						<if condition="$list">
							<volist name="list" id="vo">
								<tr class="odd gradeX" id='{$vo.id}' pid="{$vo.pid}">
									<td>
										<input type="text" class="form-control" value="{$vo.sort}">
									</td>
									<td>

										<?php $get_child = get_category_children($list,$vo['id']); ?>
										<if condition="$vo['pid'] NEQ 0">
											{:str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$vo['level'])}∟
											<if condition="$get_child NEQ NULL">
												<span class="row-details row-details-close"></span>
											</if>	
												<input type="text" class="form-control input-medium" name="title" value="{$vo.title}" style="display:inline-block">
												&nbsp;&nbsp;<a href="{:U('Category/add',array('pid'=>$vo['id']))}"><i class="glyphicon glyphicon-plus"></i></a>
										<else/>
										    <span class="row-details row-details-close"></span>&nbsp;
										    <input type="text" class="form-control input-medium" name="title" value="{$vo.title}" style="display:inline-block">
										    &nbsp;&nbsp;<a href="{:U('Category/add',array('pid'=>$vo['id']))}"><i class="glyphicon glyphicon-plus"></i></a>
										</if>
									</td>
									<td>
										<span class=""><a href="{:U('delCate',array('id'=>$vo['id']))}" onClick="if(confirm('确定删除该分类？')==false) return false;">删除</a></span>
									</td>
								</tr>
							</volist>
							<else/>
							<tr><td colspan="11" align="center">没有找到相关数据！</td></tr>
						</if>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</block>
<block name="script">
	<script type="text/javascript">
	$(function() {
		$( 'tr[pid!=0]' ).hide();

		$( '.row-details-close' ).toggle( function () {
			var index = $( this ).parents('tr').attr('id');
			$( this ).removeClass( 'row-details-close' );
			$( this ).addClass( 'row-details-open' );
			$( 'tr[pid='+ index +']' ).show();
		}, function () {
			var index = $( this ).parents('tr').attr('id');
			$( this ).removeClass( 'row-details-open' );
			$( this ).addClass( 'row-details-close' );
			$( 'tr[pid='+ index +']' ).hide();
		} );
	})

	var old_val='';
	$('.ajax-input').focus(function(){
		old_val = $(this).val();
	});
	$('.ajax-input').blur(function(){
		if(old_val != $(this).val()) {
			$.post(
				"{:U('editCate')}",
				{id: $(this).attr('id'), value: $(this).val()},
				function(data){
					if(data.status) {
						toastr['success'](data.info);
						setTimeout(function(){
							location.reload();
						},1500)
					}else{
						toastr['error'](data.info);
					}
				}
			)
		}
	});	
	</script>
</block>	